package it.koutifaris.travianmap.communication.mapdownloader;

import java.util.HashMap;
import java.util.Map;

import android.view.View;

public class DownloadProgressHelper {

	private static final DownloadProgressHelper INSTANCE = new DownloadProgressHelper();

	private final Map<String, DownloadProgressHandler> handlersMap;

	private DownloadProgressHelper() {
		handlersMap = new HashMap<String, DownloadProgressHandler>();
	}

	public static DownloadProgressHelper downloadServiceHelper() {
		return INSTANCE;
	}

	public boolean isDownloadInProgress(String serverId) {
		return (handlersMap.get(serverId) != null);
	}

	public void updateProgressHandlerIfNeeded(String serverId, View view) {
		if (isDownloadInProgress(serverId)) {
			handlersMap.get(serverId).updateUI(view);
		}
	}

	void register(String serverId, DownloadProgressHandler handler) {
		handlersMap.put(serverId, handler);
	}

	void unregister(String serverId) {
		handlersMap.remove(serverId);
	}

}
